/**
 * Filename: DoBase64Service.java
 * @author  Firefly
 * @contact postfirefly@163.com
 * @time    2016/5/15 19:05
 */
package com.github.postsanf.yinian.service;

import android.content.Intent;

import com.github.postsanf.yinian.BaseIntentService;
import com.github.postsanf.yinian.R;
import com.github.postsanf.yinian.constants.ACTIONs;
import com.github.postsanf.yinian.constants.CommonConstants;
import com.github.postsanf.yinian.constants.SelectedImg;
import com.github.postsanf.yinian.constants.YNSingleton;
import com.github.postsanf.yinian.entity.YNAlbumResponse;
import com.github.postsanf.yinian.utils.ReqUtils;
import com.github.postsanf.yinian.utils.YNImageUtils;
import com.litesuits.http.exception.HttpException;
import com.litesuits.http.listener.HttpListener;
import com.litesuits.http.request.StringRequest;
import com.litesuits.http.request.param.HttpMethods;
import com.litesuits.http.response.Response;
import java.util.LinkedHashMap;
/**
 * 图片Base64格式转化
 */
public class DoBase64Service extends BaseIntentService {

    private  int baseW = 320;
    public DoBase64Service() {
        super("DoBase64Service");
    }

    @Override
    public void onCreate(){
        super.onCreate();
    }

    @Override
    protected void onHandleIntent(Intent intent){
        if (intent != null){
            final String action = intent.getAction();
            switch(action){
                case ACTIONs.actionDoBase:
                    String   wh   = intent.getExtras().getString(ACTIONs.aWH);
                    getBase64All(wh);
                    break;
            }
        }
    }

    private void getBase64All(String wh){
        SelectedImg.base64Image.clear();
        String[] proportion = wh.split(",");
        for(int i=0;i < 20;i++){
            int height = (int) (baseW/Float.parseFloat(proportion[i]));
            SelectedImg.base64Image.add(YNImageUtils.bitmaptoString(YNImageUtils.getImageThumbnail(SelectedImg.mSelectedImage.get(i% SelectedImg.mSelectedImage.size()), baseW, height), 100));
        }
        // 转完Base64格式之后通知
        Intent upIntent = new Intent(ACTIONs.actionUpdateBase);
        sendBroadcast(upIntent);
    }

    @Override
    public void onDestroy()
    {
        super.onDestroy();
    }
}
